Background

Background

  • Git is a version control system
  • Enables managing, sharing and register code development
  • Allow traceback to old version at any time

Background

  • GitHub is an online platform to hosting projects
  • Integrates with git system
  • Enable create and sharing repositories

Background

  • Rstudio is “Integrated Development Environment”
  • Use R programming language
  • Allow integration between Git and GitHub

Creating Github account

If you haven’t account, go to (https://github.com/).

Setting git and Rstudio

  • ( Only needs to be done one time per PC 1x)
  • At Terminal, proceed with the following commands:
  • git config --global user.name “Your Name”
  • git config --global user.email “your_email@example.com”

Connect RStudio to Github

  1. In RStudio, go to Tools > Global Options… > Git/SVN
  2. Make sure Enable version control for RStudio projects is selected
  3. Make sure to point to the right path for Git executable (and don’t worry about SVN)
  4. Click on Create RSA Key… and click on Create (and don’t worry about password)
  5. Click on View public key, and press Crtl + C to copy the key to the clipboard
  6. Go to https://github.com/settings/keys and click on New SSH key
  7. Give a title to your key (identifying the computer your at), e.g. “PCname_Sist.Operacional”
  8. Paste (Crtl + V) the key from your clipboard
  9. Click on Add SSH key
  10. No Terminal, É MANDATÓRIO rodar:
  11. ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts

Connect RStudio to Github

  1. At Terminal, run: gh auth login
  2. Press ENTER until see: What is your preferred protocol for Git operations? then select SSH.
  3. Keep pressing ENTER to the next question until generate a code (copy) and press ENTER again
  4. Paste the code on terminal at window browser (maybe you need to login GitHub before) then click in the button to Authorize github

Hands on

Creating a repository

  1. Go to http://github.com/new
  2. Choose a repository name, e.g. r_sandbox
  3. Click on Private
  4. Select Add a README file
  5. Select Add .gitignore (and pick R as your .gitignore template)
  6. Click Create Repository
  7. Go to Code > SSH and copy the SSH address

Hands on

Copying a repository

  1. In RStudio, go to File > New Project… > Version Control > Git
  2. Go to the Github repository, then Code > SSH and copy the SSH address (if you haven’t done so already) instead of HTTPS
  3. Paste (Crtl + V) the SSH address for repository of interest from your clipboard
  4. If a pop-up window appears asking for username, do the gh auth login steps again (even if it says you’ve already done it)
  5. Choose the folder where your project will be saved (e.g. create a folder named git to save all your repositories in one single place)
  6. Click on Create Project
  7. In case of Git tab not appear in RStudio, after after copy a repository, you must go:
    7.1 Tools > Project options > Git/SVN, in Version control system, select Git
    7.2 At RStudio Terminal, run git remote -v e, then, run git config --global --add safe.directory

First commit

  • Go to Rstudio terminal
  • type git add . to add all files
  • type git commit -m "message" to commit message
  • type git push to push to GitHub

Tips

Warning

when open project type git pull in terminal (to update repository) before making changes

Undo a commit

  • RStudio gives a note before commit if you have files > 5MB ( Github allow send files until 25 MB).
  • If the note appear, before to proceed to push, make sure the larger files are in the .gitignore ( click with the right button on the file, then select “ignore”).
  • If you have commited the files , the push will not happen.
  • In this way, you need undo the commit, include the large file on .gitignore before to proceed.

Undo a commit

  1. git reset –soft HEAD~
  2. Tip: Add a number on the final to undo multiple commits. To undo the last 2 commits ( both are not pushed yet), run: git reset --soft HEAD~2
  3. Include large files on .gitignore and proceed with commit + push

Any Questions?

  • josetchagas@usp.br
  • Thank you!